package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.google.android.exoplayer2.C;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00105 extends BasterFragment implements OnRefreshLoadMoreListener , ClassroomDay00105Contion.vier {


    public static SmartRefreshLayout ClassroomSmartRefreshLayout;
    private RecyclerView ClassroomRecyclerView;
    public boolean  isclass=true;
    public int classnum=40;
    public int classbuju=0;
    public ClassroomDay00105Adpter adpter;
    public ClassroomDay00105Presenter presenter;


    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00105;
    }

    @Override
    public void initView() {

        ClassroomSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Classroom_SmartRefreshLayout);
        ClassroomRecyclerView = (RecyclerView) findViewById(R.id.Classroom_RecyclerView);
        ClassroomSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        ClassroomRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

      ;
        presenter = new ClassroomDay00105Presenter(this,new ClassroomDay00105Model());
        presenter.classroom("/video/findVideos?currentPage="+classnum+"&pageSize=10");




    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<ClassroomDay00105Bean.DataBean> dataBeans) {

        for (ClassroomDay00105Bean.DataBean dataBean : dataBeans) {
            dataBean.setClassroomLayout(++classbuju);
            if (classbuju==4){
                classbuju=0;
            }
        }
        ClassroomSmartRefreshLayout.finishLoadMore();
        ClassroomSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new ClassroomDay00105Adpter(dataBeans);
            ClassroomRecyclerView.setAdapter(adpter);
        }else {
            if (isclass){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isclass=false;
        classnum++;
        presenter.classroom("/video/findVideos?currentPage="+classnum+"&pageSize=10");
        Log.i("BlankFragmentDay001","-05加载:"+classnum);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (isclass){
            classnum=40;
        }
        presenter.classroom("/video/findVideos?currentPage="+classnum+"&pageSize=10");
        Log.i("BlankFragmentDay001","-05刷新:"+classnum);
    }


}
